(function () {

    //点击后退
    let back = document.querySelector('.back')

    back.addEventListener('click', function () {
        // console.log(1)
        history.back()
    })
    //发起请求 渲染页面
    $.ajax({
        url: 'http://chst.vip:1234/api/getinlanddiscount',
        success(res) {
            // console.log(res.result)
            let str = ''
            let regExp = /(?<=imgurl=)[^'"]*/
            //./DiscountParticulars.html
            res.result.forEach(item => {
                console.log(item)
                str += `
                <li productId=${item.productId}>
                    <a href="javascript:;" productId=${item.productId}>
                        ${item.productImg}
                        <div class="text">${item.productName}</div>
                        <div class="price">${item.productPrice}</div>
                        <div class="time">${item.productFrom}|${item.productTime}</div>
                    </a>

                </li>

                `
            })

            $('.info').html(str)
        }
    })

    $('.info').click(function (e) {
        // console.log(e.target.parentNode.nodeName)
        let id
        if (e.target.nodeName == 'LI') {
            id = e.target.getAttribute('productId')
        } else {
            id = e.target.parentNode.getAttribute('productId')

        }
        console.log(id)
        //将id 放在地址上
        location.href = '../pages/DiscountParticulars.html?productId=' + id
    })
})()